﻿/**
* Title:"项目";
*
* Description:
*        功能：
*
* Author:Tongwel
*
* Date:2018.6
*
* Modify:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//良好习惯养成
//凡是字典都要添加判断语句
//看是否有这key存在
namespace DemoSpace
{
    //1.建立存储ICommand的集合
    public class Controller 
    {
        //把事件放到集合里面
        private Dictionary<string, ICommand> msg2command;
        public Controller()
        {
            this.msg2command = new Dictionary<string, ICommand>();
        }
        //注册方法
        public void ResiterCommand(string msg,ICommand command)
        {
            if (!this.msg2command.ContainsKey(msg))
            {
                this.msg2command.Add(msg, command);
            }
        }
        INotifier notifier;
        public void ExecuteCommand(string msg)
        {
            if (this.msg2command.ContainsKey(msg))
            {
                msg2command[msg].Excute(notifier);
            }
        }
    }
}